package cn.com.hfuu.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.hfuu.UUIdUtil;
import cn.com.hfuu.dao.menuMapper;
import cn.com.hfuu.dao.rolemenuMapper;
import cn.com.hfuu.module.menu;
import cn.com.hfuu.module.rolemenu;

@Service("rolemenuservice")
public class RoleMenuService {

	@Autowired
	menuMapper menumap;
	
	@Autowired
	rolemenuMapper rolemenumap;
	
	
	public List<menu> selectbyrole(String roleid ){
		List<rolemenu> rolemenulist=rolemenumap.selectmenubyrole(roleid);
		List<menu> menulist = new ArrayList<menu>();
		for (rolemenu rolemenu : rolemenulist) {
			menu m=menumap.selectByPrimaryKey(rolemenu.getMenuId());
			menulist.add(m);
		}
		
		return menulist;
		
	}
	
	public List<rolemenu> selectrole(String roleid){
		return rolemenumap.selectmenubyrole(roleid);
		
	}
	
	public List<menu> selectSeconnd(String menuid){
		return menumap.selectSecond(menuid);
	}

	public void inserts(List<menu> idlist,String roleid) {
		// TODO Auto-generated method stub
		UUIdUtil id=new UUIdUtil();
		rolemenu rm=new rolemenu();
		for (menu menu : idlist) {
			rm.setRoleMenuid(id.getUuid());
			rm.setMenuId(menu.getMenuId());
			rm.setRoleId(roleid);
			rolemenumap.insert(rm);
		}
	}

	public void deletes(List<cn.com.hfuu.module.rolemenu> rolemenu) {
		// TODO Auto-generated method stub
		for (rolemenu rolemenu2 : rolemenu) {
			rolemenumap.deleteByPrimaryKey(rolemenu2.getRoleMenuid());
		}
	}

	public int deletemenuid(String id) {
		// TODO Auto-generated method stub
		return rolemenumap.deletemenuid(id);
	}

	public int deleteroleid(String[] ids) {
		// TODO Auto-generated method stub
		return rolemenumap.deleteroleid(ids);
	}
}
